package com.xuanwei.xwcommon.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author jiangyong
 * @Description TODO
 * @Date 2019/6/28 14:22
 **/
public class BeanUtil {

    public static <T, E> List<E> copyList(List<T> source, Class<E> clazz) {
        if (source == null || source.size() == 0) {
            return new ArrayList<>();
        }
        List<E> list = new ArrayList<>(source.size());
        source.forEach(s -> {
            try {
                E e = clazz.newInstance();
                BeanUtils.copyProperties(s, e);
                list.add(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        });
        return list;
    }
}
